﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using clBD;
using clEntidad;
using System.Data.OleDb;

namespace clBUS
{
    public class BUSVehiculo:BUSBase
    {
        public BUSVehiculo(String cadBD) : base(cadBD) { }

        public Vehiculo get(String codigo)
        {
            Vehiculo vehiculo = null;
            using (OleDbConnection cn = getCn())
            {
                OleDbDataReader dr = new BDVehiculo(cn).get(codigo);
                if (dr.Read())
                {
                    vehiculo = new Vehiculo();
                    vehiculo.codigo = codigo;
                    vehiculo.marca = dr.GetString(0).Trim();
                    vehiculo.llantaRpto = dr.GetInt16(1);
                    vehiculo.escaleraGrande = dr.GetInt16(2);
                    vehiculo.escaleraChica = dr.GetInt16(3);
                    vehiculo.ultimoKilometraje = dr.GetInt32(4);
                    vehiculo.estado = dr.GetString(5);
                    vehiculo.ultId = dr.GetInt32(6);
                    vehiculo.placa = dr.GetString(7);
                    if (!dr.IsDBNull(8))
                    {
                        vehiculo.tipo = dr.GetString(8);
                    }
                    if (!dr.IsDBNull(9))
                    {
                       vehiculo.numDoc=dr.GetString(9);
                    }
                    if (!dr.IsDBNull(10))
                    {
                        vehiculo.equipoIn1.numSerie = dr.GetString(10);
                    }
                    if (!dr.IsDBNull(11))
                    {
                        vehiculo.equipoIn2.numSerie = dr.GetString(11);
                    }
                }
            }
            return vehiculo;
        }
        public void grabarVarios(List<Vehiculo> elems)
        {
            using (OleDbConnection cn = getCn())
            {
                BDVehiculo objBDEqp = new BDVehiculo(cn);
                foreach (Vehiculo elem in elems)
                {
                    objBDEqp.grabar(elem);
                }
            }
        }
    }
}
